<?php


	namespace app\lib\exception;


	use think\exception\Handle;
	use think\facade\Log;
	use think\Response;
	use Throwable;

	class ExceptionHandle extends Handle
	{
		public function render ($request, Throwable $e): Response {
			if ($e instanceof ApiException) {
				return toast($e->message, $e->code, ['file' => $e->getFile(), 'line' => $e->getLine()]);
			} else if ($e instanceof ToastException) {
				return toast($e->message, $e->code, ['file' => $e->getFile(), 'line' => $e->getLine()]);
			}

			//开启debug调试模式,走原本的异常机制
			if (!env('APP_DEBUG')) {
				Log::error($e->getMessage());

				return toast('服务器内部错误', $e->getCode(), ['file' => $e->getFile(), 'line' => $e->getLine()]);
			}

			// TODO: Change the autogenerated stub
			return parent::render($request, $e);
		}
	}
